using UnityEngine;
using System.Collections;
using PathologicalGames;

public class HPNumberHUD: HUD
{
	protected UILabel hpNumber;
	public GameObject dropNumber; 

	public override void SetUp (GameObject target)
	{
		base.SetUp (target);

		if(target == null)
		{
			return;
		}
		
		
		hpNumber = GetComponent<UILabel>(); 
		Character character = target.GetComponent<Character>();
		if(character != null)
		{
			character.Property.hp.OnValueChanged += OnHealthChanged;
			hpNumber.text = character.Property.hp.ToString();
		}
	}

	public void OnHealthChanged(int currentValue, int lastValue)
	{

		if(currentValue != 0)
		{
			hpNumber.text = currentValue.ToString();
			dropNumber.GetComponent<UILabel>().text = (lastValue - currentValue).ToString();
			dropNumber.SetActive(true);
			//Debug.Log(dropNumber.transform.parent);
			dropNumber.GetComponent<UIEffect>().Play();
		}
		else
		{
			gameObject.SetActive(false); 
		}
	}
}

